<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            color: #333;
        }

        .active {
            color: red;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div class="box">文字</div>
    <script>
        // 通过classList添加 add('active') remove('active') 都是方法=API  名字()
        const box = document.querySelector('div')
        // 追加类名
        box.classList.add('active')
        // 删除一个类
        box.classList.remove('active')
        // 切换一个类
        box.classList.toggle('active')
    </script>
</body>

</html>